$(function(){

    //登录页
    getHomePageLayout();
    //弹出登录框
    $(".bannerCon ul li").click(function () {

      var url =$(this).attr('data-url');
      $('#myModal').attr('data-url',url);
      $('#myModal').modal();
    })



    //文章更多
    $('#mesNotice-more').click(function(){


        //频道layoutID
        var layoutId = $(this).parent().attr('id');
        var url = $(this).parent().attr('data-interface');
        $('#iframeModal').attr('data-layoutId',layoutId);
        $('#iframeModal').attr('data-interface',url);
        $('#iframeModal').attr('src','/init/articleList');
        $('#openModal').modal();
    });

    //文章详细
    $('.mesNotice ul li ').click(function(){
        window.open('/init/articleDetail')
    });
});

//获取登录前首页布局
function getHomePageLayout(){

    $.ajax({
        url : "/layout/getLayoutHtml",
        type : 'GET',
        dataType : "json",
        async:false,
        data : {
            pageId:'HOME_PAGE_HOME_PAGE'
        },
        success : function(data) {
            var html = data.html;
            $('#homePageHtml').html(html);
            var verifyCode = new GVerify("v_container");
        }
    })

}


//登录认证

function LoginSubmit() {
    //用户名
    var userName = $('#userName').val();
    //密码
    var passWord = $('#passWord').val();
    //CA密码
    var caPassWord = $('#caPassWord').val();
    //年度
    var nd =  $('#nd').val();

    //获取系统日期
    var date=new Date;
    var year=date.getFullYear();

    if(nd==null||nd ==undefined){
        nd=year;
    }

    //验证码

    var code =$('#code_input').val();
    // if(!verifyCode.validate(code)){
    //     $("#reminMessage").html('验证码输入错误');
    //     $("#reminMessage").css("display","block");
    //     return;
    // }

    //获取点击的登录框的链接
    var url = $('#myModal').attr('data-url');

    if(url!=null && url !=undefined && url !=''){

        //Base64 处理
        userName = antUtil.base64.encode(userName);
        url+='username='+userName;
        passWord = antUtil.base64.encode(passWord);
        url+='&password='+passWord;
        window.location.href=url;
        return;
    }else{
        $.ajax({
            url : "/loginCheck",
            type : 'GET',
            dataType : "json",
            data : {
                username:userName,
                password:passWord
            },
            success : function(data) {
                var success = data.success;
                if(success){
                    var tokenId = data.token;
                    sessionStorage['tokenId'] = tokenId;
                    sessionStorage['userId'] = userName;
                    sessionStorage['nd'] = nd;
                    window.location.href="/index";
                }else{
                    $("#reminMessage").html('用户名或密码输入错误');
                    $("#reminMessage").css("display","block");
                    return;
                }
            }
        })

    }



}


